from flask import Flask
from apps.config import env
from apps.extend import init_extend
from apps.urls import init_api


def create_app(env_name):
    app = Flask(__name__)
    app.debug = True
    app.config.from_object(env.get(env_name))
    # 环境变量的值应该是配置文件的绝对路径
    # app.config.from_envvar("F:\Flask_code\Flask_Last\config\default.py")
    init_extend(app)
    init_blue(app)
    init_view(app)
    init_api(app)
    return app

from apps.movie.views import main
"""FBV模式"""
def init_blue(app):
    app.register_blueprint(main,url_prefix = '/')

from apps.movie.views import IndexView,MovieListView,MovieDetailView
from apps.user.views import UserRegisterView,UserLoginView,UserLogoutView,UserActiveView
from apps.cinema.views import CinemaListView,CinemaDetaiView
"""CBV模式"""
def init_view(app):
    app.add_url_rule('/index/',view_func=IndexView.as_view(name='index'))
    app.add_url_rule('/user/register/',view_func=UserRegisterView.as_view(name='user_register'))
    app.add_url_rule('/user/login/',view_func=UserLoginView.as_view(name='user_login'))
    app.add_url_rule('/user/ative/',view_func=UserActiveView.as_view(name='user_ative'))
    app.add_url_rule('/user/logout/',view_func=UserLogoutView.as_view(name='user_logout'))
    app.add_url_rule('/cinema/list/',view_func=CinemaListView.as_view(name='cinema_list'))
    app.add_url_rule('/cinema/detail/',view_func=CinemaDetaiView.as_view(name='cinema_detail'))
    app.add_url_rule('/movie/list/',view_func=MovieListView.as_view(name='movie_list'))
    app.add_url_rule('/movie/detail/',view_func=MovieDetailView.as_view(name='moie_detail'))


